﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class SmsMoWaiting
    {
    	#region public properties
		[Required(ErrorMessage="MoGuid Required")]
		public Guid MoGuid { get; set; }
		public string Subs { get; set; }
		public string Message { get; set; }
		public string ShortCode { get; set; }
		public DateTime? ReceivedTime { get; set; }
		public string Status { get; set; }
		public int? OperatorID { get; set; }
		public Guid? SmsInGUID { get; set; }
		public int? CooperateID { get; set; }
		#endregion

		#region constructor
		public SmsMoWaiting(){ }

		public SmsMoWaiting(IDataReader rd)
		{
			this.MoGuid = (Guid)rd["MoGuid"];
			this.Subs = rd["Subs"].ToString();
			this.Message = rd["Message"].ToString();
			this.ShortCode = rd["ShortCode"].ToString();
			this.ReceivedTime = rd["ReceivedTime"].Equals(DBNull.Value) ? (DateTime?)null : (DateTime)rd["ReceivedTime"];
			this.Status = rd["Status"].ToString();
			this.OperatorID = rd["OperatorID"].Equals(DBNull.Value) ? (int?)null : (int)rd["OperatorID"];
			this.SmsInGUID = rd["SmsInGUID"].Equals(DBNull.Value) ? (Guid?)null : (Guid)rd["SmsInGUID"];
			this.CooperateID = rd["CooperateID"].Equals(DBNull.Value) ? (int?)null : (int)rd["CooperateID"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBSmsMoWaiting.Create(MoGuid, Subs, Message, ShortCode, ReceivedTime, Status, OperatorID, SmsInGUID, CooperateID);
        }

        private bool Update()
        {
            return DBSmsMoWaiting.Update(MoGuid, Subs, Message, ShortCode, ReceivedTime, Status, OperatorID, SmsInGUID, CooperateID);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(MoGuid != Guid.NewGuid())
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(Guid MoGuid)
        {
            return DBSmsMoWaiting.Delete(MoGuid);
        }

        public static List<SmsMoWaiting> GetAll()
        {
            return ObjectClass.CreateList<SmsMoWaiting>(DBSmsMoWaiting.GetAll());
        }

        public static SmsMoWaiting GetByKey(Guid MoGuid)
        {
            return ObjectClass.CreateInstance<SmsMoWaiting>(DBSmsMoWaiting.GetByKey(MoGuid));
        }

        public static List<SmsMoWaiting> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<SmsMoWaiting>(DBSmsMoWaiting.GetByTop(top, where, order));
        }
		#endregion
	}
}
